package com.xbongbong.saas.service.impl;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.invoicerelation.pojo.dto.InvoiceRelationshipDeleteBatchDTO;
import com.xbongbong.pro.invoicerelation.pojo.vo.InvoiceRelationshipDeleteBatchVO;
import com.xbongbong.saas.model.PurchaseInvoiceRelationshipModel;
import com.xbongbong.saas.service.PurchaseInvoiceRelationshipService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 进项发票明细service
 * @author yuqian
 */
@Service("purchaseInvoiceRelationService")
public class PurchaseInvoiceRelationshipServiceImpl implements PurchaseInvoiceRelationshipService {
    private static final Logger LOG = LoggerFactory.getLogger(PurchaseInvoiceRelationshipServiceImpl.class);

    @Resource
    private PurchaseInvoiceRelationshipModel purchaseInvoiceRelationshipModel;

    @Override
    public InvoiceRelationshipDeleteBatchVO deleteBatchByInvoiceIdIn(InvoiceRelationshipDeleteBatchDTO invoiceRelationshipDeleteBatchDTO) throws XbbException {
        InvoiceRelationshipDeleteBatchVO invoiceRelationshipDeleteBatchVO = new InvoiceRelationshipDeleteBatchVO();
        try {
            List<Long> purchaseInvoiceIdIn = invoiceRelationshipDeleteBatchDTO.getInvoiceIdIn();
            String corpid = invoiceRelationshipDeleteBatchDTO.getCorpid();
            purchaseInvoiceRelationshipModel.deleteByInvoiceIdIn(purchaseInvoiceIdIn, corpid);
        } catch (Exception e) {
            LOG.error("invoiceRelationService.deleteBatchByInvoiceIdIn 执行出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return invoiceRelationshipDeleteBatchVO;
    }
}
